﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Test.aspx.cs" Inherits="WebApplication7.Test" %>

<%@ Register src="~/UserControls/GamePannel.ascx" tagname="GamePannel" tagprefix="uc1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">   
    <title></title>
    <script src="http://js.pusherapp.com/1.9/pusher.min.js" type="text/javascript"></script>
   
</head>
<body>
    <form id="form1" runat="server" >
    <table width="975px" height="750px" cellpadding="0" cellspacing="0">
        <tr>
            <td width="700" >
             <img src=monopoly_original.jpg style="position:absolute;left:0px;top:0px;z-index:-1"/>
    <img src= player1.png id="player1" 
        style="position:absolute;top:0px;left:17px; " height="65"/>
    <img src=player2.png style="position:absolute;left:10px;top:0px;z-index:-1" 
        id="player2" height="65" />
    <img src=player3.png style="position:absolute;left:15px;top:6px;z-index:-1" 
        id="player4" height="65"/>
    <img src=player4.png style="position:absolute;left:20px;top:3px;z-index:-1" 
        id="player3" height="65"/>
    
    
    <div style="position:absolute;left:0px;top:700px;z-index:-1; width: 700px;">
       <asp:Label ID="LabelInfo" runat="server" Text="Game Info: " BackColor="Silver" 
            Font-Bold="True" Font-Size="Large" ForeColor="#333333" Height="30px" 
            Width="700px"></asp:Label>
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>
            <asp:Button ID="Button1" runat="server" Text="Button" 
                onclick="Button1_Click1" style="position:absolute;left:-10px;top:0px;z-index:-1"  />
               
            </ContentTemplate>
        </asp:UpdatePanel>
        
        <asp:HiddenField ID="HidenUserName" runat="server" />
    </div>
            </td>
            <td width="270" style="position:absolute;left:705px;top:0px;z-index:-1">
             <asp:UpdatePanel ID="UpdatePanel2" runat="server">
                <ContentTemplate>
                 <uc1:GamePannel ID="GamePannel1" runat="server" />
                  <asp:Button ID="Button2" runat="server" Text="Button"
                onclick="Button2_Click" style="position:absolute;left:-5000px;top:0px;z-index:-1"/>
                <asp:Button ID="Button3" runat="server" Text="Button"
                onclick="Button3_Click" style="position:absolute;left:-5000px;top:0px;z-index:-1"/>
                 </ContentTemplate>
                </asp:UpdatePanel>
            </td>
        </tr>
    </table>
   
    
    </form>
     
    
</body>
 <script type="text/javascript">
     // Enable pusher logging - don't include this in production
     var userWidth = window.screen.width;
     var userName = '<%=Session["username"]%>';
     document.getElementById("HidenUserName").value = '<%=Session["username"]%>';
     

     function movePlayer(data) {
         var obj = JSON.parse(data);
         var pp = document.getElementById(obj.player);
         pp.style.left = obj.left + "px";
         pp.style.top = obj.top + "px";
     }

     function rollTheDice(data) {
         var btn2 = document.getElementById("Button2");
         btn2.click();
         if (confirm('It\' your turn! Roll the Dice!')) {
             var btn = document.getElementById("Button1");
             btn.click();
         }
         else {
             var btn3 = document.getElementById("Button3");
             btn3.click();
         }
     }

     Pusher.log = function (message) {
         if (window.console && window.console.log) window.console.log(message);
     };

     // Flash fallback logging - don't include this in production
     WEB_SOCKET_DEBUG = true;

     var pusher = new Pusher('a1b663c201ac667143ce');
     var channel = pusher.subscribe('broadcast');
     channel.bind('moveIt', function (data) {
             movePlayer(data);
     });

     channel.bind('ask_roll_dice', function (data) {
         if (data == userName) {
             rollTheDice(data);
         }
         else {
             var btn2 = document.getElementById("Button2");
             btn2.click();
         }
     });

     channel.bind('info', function (data) {
         document.getElementById('<%=LabelInfo.ClientID %>').innerText = "     Info: "+data;
     });

  </script>
</html>
